package feifei.controller;

import feifei.pojo.User;
import feifei.service.UserService;
import feifei.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

@Controller
public class UserController {
    UserService us=new UserServiceImpl();
    @RequestMapping(value = "/login")
    @ResponseBody
    public String login(HttpServletRequest req ,HttpServletResponse resp) throws Exception {
        req.setCharacterEncoding("utf8");
        resp.setCharacterEncoding("utf8");
        String uname = req.getParameter("uname");
        String upwd = req.getParameter("upwd");
        if (uname != null && upwd != null) {
            User u = us.login(uname, upwd);
            if (u != null) {
                resp.sendRedirect("main.jsp");
            }
            return "Password wrong";
        }
        return "Username or password is void";
    }
    @RequestMapping(value = "/quit")
    public String quit()
    {
        return "login";
    }
}
